package com.supercube.sport.yoga.controller;

import com.supercube.common.controller.BaseController;
import com.supercube.common.utils.StringUtils;
import com.supercube.sport.yoga.domain.EmpSalaryDesignDTO;
import com.supercube.sport.yoga.service.EmpSalaryDesignService;
import com.supercube.sport.yoga.utils.ResultInfo;
import com.supercube.sport.yoga.vo.EmpSalaryDesignVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/empSalaryDesign")
@Api(tags = "员工薪资设置")
public class EmpSalaryDesignController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    EmpSalaryDesignService empSalaryDesignService;

    @ApiOperation(value = "保存/修改薪酬设置信息", notes = "保存/修改薪酬设置信息")
    @PostMapping("/save")
    public ResultInfo save(@RequestBody EmpSalaryDesignDTO dto) {
        EmpSalaryDesignVO empSalaryDesignVO = empSalaryDesignService.queryEmpSalaryDesignByEmpId(dto.getEmpId());
        if (empSalaryDesignVO != null) {
            empSalaryDesignService.update(dto);
        } else {
            dto.setId(StringUtils.getUUID());
            empSalaryDesignService.save(dto);
        }
        return ResultInfo.success("保存成功");
    }

    @ApiOperation(value = "查询薪酬设置信息，根据员工empId", notes = "查询薪酬设置信息，根据员工empId")
    @GetMapping("/queryEmpSalaryDesignByEmpId")
    public ResultInfo querySalaryDesignById(@RequestParam("empId") Long empId) {
        if (empId == null) {
            return ResultInfo.validateFailed();
        }
        EmpSalaryDesignVO empSalaryDesignVO = empSalaryDesignService.queryEmpSalaryDesignByEmpId(empId);
        return ResultInfo.success(empSalaryDesignVO);
    }
}
